package com.gshg.log.cleanlog.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.Date;

@Slf4j
public class FileNameDealUtils {

    public static String getFileContainDate(String fileName,  String dateFormat){
        Date nowDate = new Date();
        String nowYear = DateUtil.dateFormatString("yyyy", nowDate);
        boolean isCheckFileName = false;

        for(int i=0; i<5; i++){
            if(fileName.contains(nowYear)){
                isCheckFileName = true;
                break;
            }else{
                nowYear = DateUtil.dateFormatString("yyyy", DateUtil.getDateBeforeSomeYear(nowDate, (-1-i)));
            }
        }

        if(!isCheckFileName){
            return "";
        }
        int start = fileName.indexOf(nowYear);
        String result = fileName.substring(start, start+dateFormat.length());

        return result;
    }


    public static String getFileContainDate(String fileName, int subStart, int subEnd){
        log.info(fileName+">>>"+subStart+">>>>"+subEnd);
        return fileName.substring(subStart, subEnd);
    }
}
